namespace ProjectThuCung.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddClassEdit1 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.HoaDon",
                c => new
                    {
                        HoaDonID = c.Int(nullable: false, identity: true),
                        TenNguoiMua = c.String(nullable: false, maxLength: 56),
                        UserId = c.Int(nullable: false),
                        DienThoai = c.String(nullable: false, maxLength: 16),
                        DiaChi = c.String(nullable: false, maxLength: 128),
                        ThoiGianGiaoHang = c.DateTime(nullable: false),
                        Dagiao = c.Boolean(nullable: false),
                        TongTien = c.Single(nullable: false),
                    })
                .PrimaryKey(t => t.HoaDonID)
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.UserProfile",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(nullable: false, maxLength: 56),
                        GroupProfile_GroupID = c.Int(),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.GroupProfile", t => t.GroupProfile_GroupID)
                .Index(t => t.GroupProfile_GroupID);
            
            CreateTable(
                "dbo.CTHoaDon",
                c => new
                    {
                        CTHoaDonID = c.Int(nullable: false, identity: true),
                        HoaDonID = c.Int(nullable: false),
                        SanPhamID = c.Int(nullable: false),
                        GiaBan = c.Single(nullable: false),
                        Soluong = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.CTHoaDonID)
                .ForeignKey("dbo.HoaDon", t => t.HoaDonID, cascadeDelete: true)
                .ForeignKey("dbo.SanPham", t => t.SanPhamID, cascadeDelete: true)
                .Index(t => t.HoaDonID)
                .Index(t => t.SanPhamID);
            
            CreateTable(
                "dbo.SanPham",
                c => new
                    {
                        SanPhamID = c.Int(nullable: false, identity: true),
                        TenSanPham = c.String(nullable: false, maxLength: 56),
                        MoTa = c.String(maxLength: 3000),
                        HinhAnh = c.String(maxLength: 255),
                        Gia = c.Single(nullable: false),
                        SoLuong = c.Int(nullable: false),
                        XuatXuID = c.Int(nullable: false),
                        LoaiSanPhamID = c.Int(nullable: false),
                        ThongTinThemID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.SanPhamID)
                .ForeignKey("dbo.LoaiSanPham", t => t.LoaiSanPhamID, cascadeDelete: true)
                .ForeignKey("dbo.XuatXu", t => t.XuatXuID, cascadeDelete: true)
                .ForeignKey("dbo.ThongTinThem", t => t.ThongTinThemID, cascadeDelete: true)
                .Index(t => t.LoaiSanPhamID)
                .Index(t => t.XuatXuID)
                .Index(t => t.ThongTinThemID);
            
            CreateTable(
                "dbo.LoaiSanPham",
                c => new
                    {
                        LoaiSanPhamID = c.Int(nullable: false, identity: true),
                        TenLoaiSanPham = c.String(nullable: false, maxLength: 56),
                        ThuocTinh = c.String(nullable: false, maxLength: 3000),
                        SubLoaiSanPham = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.LoaiSanPhamID);
            
            CreateTable(
                "dbo.XuatXu",
                c => new
                    {
                        XuatXuID = c.Int(nullable: false, identity: true),
                        TenXuatXu = c.String(nullable: false, maxLength: 56),
                        DiaChi = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.XuatXuID);
            
            CreateTable(
                "dbo.ThongTinThem",
                c => new
                    {
                        ThongTinThemID = c.Int(nullable: false, identity: true),
                        Giong = c.String(nullable: false, maxLength: 56),
                        GioiTinh = c.Boolean(nullable: false),
                        ThangTuoi = c.Int(nullable: false),
                        Mau = c.String(nullable: false, maxLength: 20),
                        TrongLuong = c.Single(nullable: false),
                    })
                .PrimaryKey(t => t.ThongTinThemID);
            
            CreateTable(
                "dbo.BinhLuanSanPham",
                c => new
                    {
                        BinhLuanSanPhamID = c.Int(nullable: false, identity: true),
                        SanPhamID = c.Int(nullable: false),
                        TenNguoiBinhLuan = c.String(nullable: false, maxLength: 56),
                        UserId = c.Int(nullable: false),
                        TieuDe = c.String(nullable: false, maxLength: 128),
                        NoiDung = c.String(nullable: false, maxLength: 2000),
                        ThoiGian = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.BinhLuanSanPhamID)
                .ForeignKey("dbo.SanPham", t => t.SanPhamID, cascadeDelete: true)
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .Index(t => t.SanPhamID)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.BaiViet",
                c => new
                    {
                        BaiVietID = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        TenNguoiViet = c.String(nullable: false, maxLength: 56),
                        TieuDe = c.String(nullable: false, maxLength: 128),
                        NoiDung = c.String(nullable: false),
                        ThoiGian = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.BaiVietID)
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.BinhLuanBaiViet",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        BaiVietID = c.Int(nullable: false),
                        UserId = c.Int(),
                        UserName = c.String(nullable: false, maxLength: 56),
                        NoiDung = c.String(nullable: false, maxLength: 2000),
                        ThoiGian = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.BaiViet", t => t.BaiVietID, cascadeDelete: true)
                .ForeignKey("dbo.UserProfile", t => t.UserId)
                .Index(t => t.BaiVietID)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.PhanLoaiVatPham",
                c => new
                    {
                        PhanLoaiVatPhamID = c.Int(nullable: false, identity: true),
                        VatPhamID = c.Int(nullable: false),
                        LoaiVatPhamID = c.Int(nullable: false),
                        TenLoaiVatPham = c.String(nullable: false, maxLength: 56),
                        LoaiThuCungID = c.Int(nullable: false),
                        TenLoaiThuCung = c.String(nullable: false, maxLength: 56),
                        VatPham_SanPhamID = c.Int(),
                        LoaiThuCung_LoaiSanPhamID = c.Int(),
                        LoaiVatPham_LoaiSanPhamID = c.Int(),
                    })
                .PrimaryKey(t => t.PhanLoaiVatPhamID)
                .ForeignKey("dbo.SanPham", t => t.VatPham_SanPhamID)
                .ForeignKey("dbo.LoaiSanPham", t => t.LoaiThuCung_LoaiSanPhamID)
                .ForeignKey("dbo.LoaiSanPham", t => t.LoaiVatPham_LoaiSanPhamID)
                .Index(t => t.VatPham_SanPhamID)
                .Index(t => t.LoaiThuCung_LoaiSanPhamID)
                .Index(t => t.LoaiVatPham_LoaiSanPhamID);
            
            CreateTable(
                "dbo.Group",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        GroupID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.GroupProfile", t => t.GroupID, cascadeDelete: true)
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .Index(t => t.GroupID)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.GroupProfile",
                c => new
                    {
                        GroupID = c.Int(nullable: false, identity: true),
                        GroupName = c.String(nullable: false, maxLength: 56),
                    })
                .PrimaryKey(t => t.GroupID);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Group", new[] { "UserId" });
            DropIndex("dbo.Group", new[] { "GroupID" });
            DropIndex("dbo.PhanLoaiVatPham", new[] { "LoaiVatPham_LoaiSanPhamID" });
            DropIndex("dbo.PhanLoaiVatPham", new[] { "LoaiThuCung_LoaiSanPhamID" });
            DropIndex("dbo.PhanLoaiVatPham", new[] { "VatPham_SanPhamID" });
            DropIndex("dbo.BinhLuanBaiViet", new[] { "UserId" });
            DropIndex("dbo.BinhLuanBaiViet", new[] { "BaiVietID" });
            DropIndex("dbo.BaiViet", new[] { "UserId" });
            DropIndex("dbo.BinhLuanSanPham", new[] { "UserId" });
            DropIndex("dbo.BinhLuanSanPham", new[] { "SanPhamID" });
            DropIndex("dbo.SanPham", new[] { "ThongTinThemID" });
            DropIndex("dbo.SanPham", new[] { "XuatXuID" });
            DropIndex("dbo.SanPham", new[] { "LoaiSanPhamID" });
            DropIndex("dbo.CTHoaDon", new[] { "SanPhamID" });
            DropIndex("dbo.CTHoaDon", new[] { "HoaDonID" });
            DropIndex("dbo.UserProfile", new[] { "GroupProfile_GroupID" });
            DropIndex("dbo.HoaDon", new[] { "UserId" });
            DropForeignKey("dbo.Group", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.Group", "GroupID", "dbo.GroupProfile");
            DropForeignKey("dbo.PhanLoaiVatPham", "LoaiVatPham_LoaiSanPhamID", "dbo.LoaiSanPham");
            DropForeignKey("dbo.PhanLoaiVatPham", "LoaiThuCung_LoaiSanPhamID", "dbo.LoaiSanPham");
            DropForeignKey("dbo.PhanLoaiVatPham", "VatPham_SanPhamID", "dbo.SanPham");
            DropForeignKey("dbo.BinhLuanBaiViet", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.BinhLuanBaiViet", "BaiVietID", "dbo.BaiViet");
            DropForeignKey("dbo.BaiViet", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.BinhLuanSanPham", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.BinhLuanSanPham", "SanPhamID", "dbo.SanPham");
            DropForeignKey("dbo.SanPham", "ThongTinThemID", "dbo.ThongTinThem");
            DropForeignKey("dbo.SanPham", "XuatXuID", "dbo.XuatXu");
            DropForeignKey("dbo.SanPham", "LoaiSanPhamID", "dbo.LoaiSanPham");
            DropForeignKey("dbo.CTHoaDon", "SanPhamID", "dbo.SanPham");
            DropForeignKey("dbo.CTHoaDon", "HoaDonID", "dbo.HoaDon");
            DropForeignKey("dbo.UserProfile", "GroupProfile_GroupID", "dbo.GroupProfile");
            DropForeignKey("dbo.HoaDon", "UserId", "dbo.UserProfile");
            DropTable("dbo.GroupProfile");
            DropTable("dbo.Group");
            DropTable("dbo.PhanLoaiVatPham");
            DropTable("dbo.BinhLuanBaiViet");
            DropTable("dbo.BaiViet");
            DropTable("dbo.BinhLuanSanPham");
            DropTable("dbo.ThongTinThem");
            DropTable("dbo.XuatXu");
            DropTable("dbo.LoaiSanPham");
            DropTable("dbo.SanPham");
            DropTable("dbo.CTHoaDon");
            DropTable("dbo.UserProfile");
            DropTable("dbo.HoaDon");
        }
    }
}
